package com.itheima.dao;

import com.itheima.pojo.Role;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface RoleDao {
    @Select("select r.* from t_role r,t_user_role ur where ur.user_id = #{userId} and r.id = ur.role_id ")
    public Set<Role> findByUserId(Integer userId);

    @Select("select t_role.name from t_role where id in (select role_id from t_user_role where user_id = #{userId})")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "keyword",column = "keyword"),
            @Result(
                    column = "id",
                    property = "permissions",
                    javaType = List.class,
                    many=@Many(select = "com.itheima.dao.PermissionDao.findByRoleId")
            )
    })
    public Set<Role> findByUserId1(Integer userId);
}
